<?php
namespace Api
{
    /**
     * Redirecting class
     */
     class  Redirect
     {
        /**
         * Redirect to specific module by followed vars
         */
         static public function CreateRedirect($module, $controller, $action='index')
         {
            $config = \Api\Config::Load();
            $htaccess = new \Api\Htaccess($config);
            if(false !== ($page = $htaccess->matchingURL(array($module,$controller,$action))))
            {
               // header('Location: http://'.$_SERVER['HTTP_HOST'].'/'.$module.'/'.$controller.'/'.$action);
               header('Location: http://'.$_SERVER['HTTP_HOST'].'/'.$page['module'].'/'.$page['mask']);
            }
            else
            {
                throw new \Exception('REDIRECT: Undefined page ['.$module.'|'.$controller.'|'.$action.']');
            }
         }
         
        /**
         * Create redirect to specific action in curently loaded
         * module and controller
         */
         static public function ToAction($action)
         {
            self::CreateRedirect(
                \Api\Config::$param[\Api\ObjectLoader::C_MODULE],
                \Api\Config::$param[\Api\ObjectLoader::C_CONTROLLER],
                $action);
         }
     }
}
?>